<?php
namespace Admin\Controller;
use Think\Controller;
class CompanyController extends BaseController {
    public function index(){
        $this->login_verify();
        // 案例展示
        $example=M('example');
        $H5Data=$example->where('type=1')->select();
        $UiData=$example->where('type=2')->select();
        $AppData=$example->where('type=3')->select();
        $JavaData=$example->where('type=4')->select();
        //var_dump($hotData);
        $this->assign('H5Data',$H5Data);
        $this->assign('UiData',$UiData);
        $this->assign('AppData',$AppData);
        $this->assign('JavaData',$JavaData);

        //获取activetype以实现设置完可查看上传的信息：
        $activeType=$_GET['activeType'];
        if (empty($activeType)) {
            $activeType=1;
        } else {
            $activeType=$_GET['activeType'];
        }
        // var_dump($activeType);
        $this->assign('activeType',$activeType);
        $this->display();
    }

    public function exampleSet(){
        $example=M('example');
        $data['exampleTitle']=$_POST['exampleTitle'];
        $data['exampleContent']=$_POST['exampleContent'];
        $data['type']=$_POST['type'];
        $data['exampleDate']=date("Y-m-d");

        $upload = new \Think\Upload();// 实例化上传类
        $upload->maxSize   =     2145728 ;// 设置附件上传大小
        $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
        $upload->saveName = 'time';// 采用时间戳命名
        $upload->rootPath  =      './Uploads/'; // 设置附件上传根目录
        $upload->subName  =      'example'; // 设置附件上传（子）目录
        // 上传单个文件 
        $info   =   $upload->uploadOne($_FILES['imgurl']);
        if(!$info) {// 上传错误提示错误信息
            $this->error($upload->getError());
        }else{// 上传成功 获取上传文件信息
            $data['imgurl']='Uploads/'.$info['savepath'].$info['savename'];
            $result=$example->add($data);    
            if($result) {
                //保存成功
                $this->success("设置成功！",U('Company/index',array('activeType'=>$data['type'])));
            }else {
                //保存失败
                $this->error("设置失败。");
            }
        }
    }

    public function exampleDel(){
        //var_dump($_GET);
        $example=M('example');
        $id=$_GET['id'];
        $data=$example->where("Id=".$id)->select();
        $activeType=$data[0]["type"];
        // var_dump($activeType);
        $result=$example->where("Id=".$id)->delete();
        if($result) {
            //保存成功
            $this->success("删除成功！",U('Company/index',array('activeType'=>$activeType)));
        }else {
            //保存失败
            $this->error("删除失败。");
        }
    }
}